package com.ffapp.rainmonitorcustom.bean;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

public class AlarmTypeBean extends BasisBean {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    private ArrayList<BaseListData> listKeyValue;

    private Map<String, String> type;

    public Map<String, String> getType() {
        return type;
    }

    public void setType(Map<String, String> type) {
        this.type = type;
    }

    public void processData() {
        type = sortMapByKey(type);
        listKeyValue = new ArrayList<>();
        BaseListData baseListData;
        for (String key : type.keySet()) {
            baseListData = new BaseListData(key, type.get(key));
            listKeyValue.add(baseListData);
        }
    }

    /**
     * 使用 Map按key进行排序
     *
     * @param map
     * @return
     */
    public static Map<String, String> sortMapByKey(Map<String, String> map) {
        if (map == null || map.isEmpty()) {
            return null;
        }

        Map<String, String> sortMap = new TreeMap<String, String>(
                new MapKeyComparator());

        sortMap.putAll(map);

        return sortMap;
    }

    public ArrayList<BaseListData> getListKeyValue() {
        return listKeyValue;
    }

    public void setListKeyValue(ArrayList<BaseListData> listKeyValue) {
        this.listKeyValue = listKeyValue;
    }

    //比较器类
    static class MapKeyComparator implements Comparator<String> {

        @Override
        public int compare(String str1, String str2) {

            return str1.compareTo(str2);
        }
    }
}
